package com.web44.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web44.ssm.bean.Book;
import com.web44.ssm.bean.QueryVo;
import com.web44.ssm.mapper.BookMapper;
import com.web44.ssm.service.IBookSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Title: BookSevice
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/15 13:41
 */
@Service
@Transactional
public class BookSevice implements IBookSevice {
    @Autowired
    private BookMapper bookMapper;
    @Override
    public void saveBook(Book book) {
        bookMapper.saveBook(book);
    }

    @Override
    public void editBook(Book book) {
        bookMapper.editBook(book);
    }

    @Override
    public void deleteBookById(Integer id) {
        bookMapper.deleteBookById(id);
    }

    @Override
    public Book queryBookById(Integer id) {
        return    bookMapper.queryBookById(id);
    }

    @Override
    public List<Book> queryBooks() {
        return bookMapper.queryBooks();
    }

    @Override
    public PageInfo<Book> queryBooksByPage(QueryVo queryVo) {
        PageHelper.startPage(queryVo.getPageNo(),queryVo.getSize());
        List<Book> books = bookMapper.queryBooks();
        PageInfo<Book> pageInfo = new PageInfo<>(books,5);
        return pageInfo;
    }
}
